package com.wisdytech.linkdcs.equipLifeCycle.maintain.action;


import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.handler.ResourceMatchingService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.model.RepairPlan;
import com.wisdytech.linkdcs.equipLifeCycle.maintain.service.IRepairPlanService;
import com.wisdytech.linkdcs.equipment.model.Equipment;
import com.wisdytech.linkdcs.partLife.model.Part;
import com.wisdytech.linkdcs.system.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghailin
 * @since 2018-07-17
 */
@Controller
@RequestMapping("/equipment/repairPlan")
public class RepairPlanAction {

    @Resource
    private IRepairPlanService repairPlanService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
     * 设备停机计划
     * @param model model
     * @return page
     */
    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "lifeCycle/equipLifeCycle/maintain/repairPlan";
    }

    @RequestMapping("/findRepairPlanByPage/get.mvc")
    @ResponseBody
    public StandardTableResult<RepairPlan> findRepairPlanByPage(String equipCode,String equipName,String maintenanceProject,String dutyDepartment,String maintenanceStartDate, String maintenanceEndDate, Filter filter) {
        PageInfo<RepairPlan> page = this.repairPlanService.findRepairPlanByPage(equipCode,equipName,maintenanceProject,dutyDepartment,maintenanceStartDate,maintenanceEndDate,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }


    @RequestMapping("/findPartByPage/get.mvc")
    @ResponseBody
    public StandardTableResult<Part> findPartByPage(String search, Filter filter) {
        PageInfo<Part> page = this.repairPlanService.findPartByPage(search,filter);
        return new StandardTableResult<>(page.getTotal(),page.getList());
    }

    @RequestMapping("/saveOrUpdateRepairPlan/save.mvc")
    @ResponseBody
    public StandardResult saveOrUpdateRepairPlan(RepairPlan repairPlan) {
        SysUser operator = BaseUtil.getCurrentUser();
        this.repairPlanService.saveOrUpdateRepairPlan(repairPlan,operator);
        return StandardResult.getSuccessResult();
    }

    @RequestMapping("/findRepairPlanById/get.mvc")
    @ResponseBody
    public StandardResult findRepairPlanById(String pkId) {
        RepairPlan repairPlan = this.repairPlanService.findRepairPlanById(pkId);
        return StandardResult.getSuccessResult(repairPlan);
    }

    @RequestMapping("/logicDeleteRepairPlanByPkIds/del.mvc")
    @ResponseBody
    public StandardResult logicDeleteRepairPlanByPkIds(String pkIds) {
        this.repairPlanService.logicDeleteRepairPlanByPkIds(pkIds);
        return StandardResult.getSuccessResult();
    }

    @RequestMapping("/fingEquipInfoByEquipCode/get.mvc")
    @ResponseBody
    public StandardResult fingEquipInfoByEquipCode(String equipCode) {
        Equipment equipment = this.repairPlanService.fingEquipInfoByEquipCode(equipCode);
        return StandardResult.getSuccessResult(equipment);
    }

}

